#include <windows.h>
#include "resource.h"
#include "clsZoomMgr.h"


clsZoomMgr::clsZoomMgr(
	CbShowStatusDelegate ^pCBSS,
	CbSwitchUIPageByTypeDelegate ^pCBSUI,
	CbUpdateUserListDelegate ^pCBUUL,
	CbClearnUpUserListDelegate ^pCBCUUL
)
{
	using System::IntPtr;
	using System::Runtime::InteropServices::Marshal;
	m_pSink = new TheCallBacks();


	IntPtr cbPtr0 = Marshal::GetFunctionPointerForDelegate(pCBSS);
	IntPtr cbPtr1 = Marshal::GetFunctionPointerForDelegate(pCBSUI);
	IntPtr cbPtr2 = Marshal::GetFunctionPointerForDelegate(pCBUUL);
	IntPtr cbPtr3 = Marshal::GetFunctionPointerForDelegate(pCBUUL);
	m_pSink->CleanUpUserList = static_cast<CB_CLEANUPUSERLIST>(Marshal::GetFunctionPointerForDelegate(pCBCUUL).ToPointer());
	m_pSink->ShowStatus = static_cast<CB_SHOWSTATUS>(Marshal::GetFunctionPointerForDelegate(pCBSS).ToPointer());
	m_pSink->SwitchUIPageByType = static_cast<CB_SWITCHUIPAGEBYTYPE>(Marshal::GetFunctionPointerForDelegate(pCBSUI).ToPointer());
	m_pSink->UpdateUserList = static_cast<CB_UPDATEUSERLIST>(Marshal::GetFunctionPointerForDelegate(pCBUUL).ToPointer());

	m_pAuthServiceMgr = new CAuthServiceMgr(m_pSink);
	m_pMeetingServiceMgr = new CMeetingServiceMgr(m_pSink);
	m_preMeetingServiceMgr = new CPreMeetingServiceMgr(m_pSink);

}
extern HINSTANCE hDll;


int clsZoomMgr::init(const wchar_t* domain,const wchar_t* apikey, const wchar_t* apisec) 
{
	//authsrv->Init()
	m_pSink->ShowStatus(0, L"clsZoomMgr::init");

	ZOOM_SDK_NAMESPACE::InitParam initParam;
	initParam.strWebDomain = domain; // L"www.ultralinked.com";//domain;//
	initParam.strBrandingName = L"Ultralinked";
	initParam.strSupportUrl = L"http://www.ultralinked.com/support";
	initParam.uiWindowIconBigID = IDI_ICON2;
	initParam.uiWindowIconSmallID = IDI_ICON2;
	initParam.hResInstance = hDll;//GetModuleHandle(NULL);
	if (m_pAuthServiceMgr)
		m_bSDKInit = m_pAuthServiceMgr->Init(initParam);

	ZOOM_SDK_NAMESPACE::AuthParam authParam;
	authParam.appKey = apikey;
	authParam.appSecret = apisec;
	int ret = m_pAuthServiceMgr->SDKAuth(authParam) ? 0 : -1;
	m_pSink->ShowStatus(ret, L"clsZoomMgr::init ret ");

	return ret;

}


int clsZoomMgr::Login(const wchar_t* email,const wchar_t* password,bool memberme)
{
	m_pSink->ShowStatus(0, L"clsZoomMgr::login");
	m_pMeetingServiceMgr->Init();

	ZOOM_SDK_NAMESPACE::LoginParam param;

	param.userName = email;
	param.password = password;
	param.bRememberMe = memberme;
	int ret = m_pAuthServiceMgr->Login(param) ? 0 : -1;
	m_pSink->ShowStatus(ret, L"clsZoomMgr::login ret:");

	return ret;
}

